*This file creates the panel data used in the analysis. All the original files can be obtained from lissdata.nl
*ADJUST THE DIRECTORY TO YOUR OWN WORKING DIRECTORY
cd "C:\Users\ev42\Dropbox\Liss\Data"


*Housing surveys
use "cd08a_EN_1.2p.dta", clear
append using "cd09b_EN_1.0p.dta" "cd10c_EN_1.1p.dta" "cd11d_EN_2.0p.dta" "cd12e_EN_1.0p.dta" "cd13f_EN_1.1p.dta" "cd14g_EN_1.1p.dta" "cd15h_EN_1.0p.dta" "cd16i_EN_1.0p.dta" "cd17j_EN_1.0p.dta" "cd18k_EN_1.0p.dta" "cd19l_EN_2.0p.dta" "cd20m_EN_1.0p.dta" "cd21n_EN_1.0p.dta"

egen rentGWE=rowmax (cd08a009 cd10c009 cd12e009 cd13f009 cd14g009 cd09b009 cd11d009 cd21n009 cd17j009 cd20m009 cd18k009 cd15h009 cd19l009 cd16i009)
replace rentGWE=rentGWE-1
label define rentG 0 "GWE Included" 1 "GWE Not included"
label values rentGWE rentG 
mvdecode rentGWE , mv(-10 98)

egen rentown = rowmax(cd11d003 cd13f003 cd10c003 cd09b003 cd12e003 cd14g003 cd15h003 cd08a003 cd18k003 cd17j003 cd21n003 cd19l003 cd20m003 cd16i003)
label values rentown cd08a003

egen heatadequate = rowmax(cd10c043 cd14g043 cd20m043 cd18k043  cd21n043 cd17j043 cd09b043 cd16i043  cd15h043  cd19l043 cd12e043  cd11d043  cd13f043 cd08a042)

egen dwelling= rowmax (cd12e038 cd15h038 cd11d038 cd10c038 cd14g038 cd08a038 cd13f038 cd09b038 cd17j038 cd20m038 cd19l038 cd21n038 cd18k038 cd16i038)

label values dwelling cd12e038

egen service =rowmax(cd09b030 cd11d030 cd10c030 cd12e030 cd08a030 cd13f030 cd15h030 cd14g030 cd20m030 cd17j030 cd19l030 cd16i030 cd18k030)
label values service cd09b030

egen dwellingyr = rowmax (cd17j036 cd14g036 cd11d036 cd08a036 cd16i036 cd13f036 cd12e036 cd19l036 cd21n036 cd10c036 cd20m036 cd09b036 cd18k036 cd15h036)
label variable dwellingyr "What year moved in current residence"

egen yrmohou=rowmax(cd08a_m cd09b_m cd10c_m cd11d_m cd12e_m cd13f_m cd14g_m cd15h_m cd16i_m cd17j_m cd18k_m cd19l_m cd20m_m cd21n_m)
label variable yrmohou "Year and Month of Housing Survey"
 
 gen year=round(yrmohou/100)
 
 
 keep nomem_encr rentGWE-year
   save "housevars.dta", replace

*Background variables
  
 use "Background\avars_200812_EN_2.0p.dta", clear

append using "Background\avars_200912_EN_2.0p.dta" "Background\avars_201012_EN_2.0p.dta" ///
"Background\avars_201112_EN_2.0p.dta" "Background\avars_201212_EN_1.0p.dta" ///
"Background\avars_201312_EN_1.0p.dta" "Background\avars_201512_EN_1.0p.dta" ///
"Background\avars_201612_EN_1.0p.dta" "Background\avars_201712_EN_1.0p.dta" ///
"Background\avars_201812_EN_1.0p.dta" "Background\avars_201912_EN_1.0p.dta" ///
"Background\avars_202012_EN_1.0p.dta" 
 
  gen year=(wave-12)/100
 
  save "backvars.dta", replace
 
 
 *Income Surveys
 use "Income\ci08a_1.0p_EN.dta", clear
 
 append using "Income\ci09b_EN_1.1p.dta" "Income\ci10c_EN_1.0p.dta" "Income\ci11d_EN_1.0p.dta" "Income\ci12e_1.0p_EN.dta" "Income\ci13f_EN_1.2p.dta" "Income\ci14g_1.0p_EN.dta" "Income\ci15h_EN_2.0p.dta" "Income\ci16i_EN_2.0p.dta" "Income\ci17j_EN_2.0p.dta" "Income\ci18k_EN_1.0p.dta" "Income\ci19l_EN_2.0p.dta" "Income\ci20m_EN_1.0p.dta" "Income\ci21n_EN_1.0p.dta"
 
 egen finstruggle= rowmax(ci20m249 ci20m248 ci20m247 ci17j245 ci20m246 ci20m245 ci14g245 ci14g246  ci14g247 ci14g248 ci14g249 ci21n249 ci21n248 ci12e247 ci21n247 ci21n246 ci21n245 ci08a245 ci08a246 ci08a247 ci08a248 ci08a249 ci11d245 ci11d246 ci12e245 ci09b248 ci11d247 ci11d248 ci09b247 ci09b249 ci09b246 ci09b245 ci11d249 ci12e248 ci19l249 ci10c246 ci19l248 ci10c247 ci19l247  ci19l246 ci19l245 ci10c245 ci17j249 ci15h245 ci15h246 ci15h247 ci15h248 ci15h249  ci17j248 ci10c248  ci12e249 ci12e246 ci18k249 ci10c249 ci18k248 ci16i249 ci16i248 ci18k247 ci16i247 ci13f249 ci18k246 ci13f248 ci13f247 ci13f246 ci13f245 ci16i246 ci18k245 ci16i245 ci17j247 ci17j246)

label variable finstruggle "Struggles with financial issues"
 
 egen heathome=rowmax(ci18k353 ci13f353 ci12e353 ci15h353 ci14g353 ci20m353 ci16i353 ci17j353 ci19l353 ci21n353)
 label variable heathome "Able to heat home well"
 
 egen arrearsutil = rowmax(ci08a303 ci09b303 ci10c303 ci11d303 ci12e303 ci13f303 ci14g303 ci15h303 ci16i303 ci17j303 ci18k303 ci19l303 ci20m303 ci21n303)
 label variable arrearsutil "Did you fall behind in utilities for two months"
 
 egen payutil = rowmax(ci20m248  ci14g248 ci21n248 ci08a248  ci09b248 ci11d248 ci12e248 ci19l248 ci15h248  ci17j248 ci10c248  ci18k248  ci16i248 ci13f248)
 label variable payutil "Running behind paying rent/mortgage/utilities"
 
egen arrearsutilb =rowmax(ci21n294 ci20m294  ci19l294 ci18k294 ci17j294  ci16i294  ci15h294  ci14g294 ci13f294  ci12e294 ci11d294 ci10c294 ci09b294 ci08a294)
  label variable arrearsutil "Are you in arrears on utilities?"

 
 egen finstrugindex= rowtotal(ci20m249 ci20m248 ci20m247 ci17j245 ci20m246 ci20m245 ci14g245 ci14g246  ci14g247 ci14g248 ci14g249 ci21n249 ci21n248 ci12e247 ci21n247 ci21n246 ci21n245 ci08a245 ci08a246 ci08a247 ci08a248 ci08a249 ci11d245 ci11d246 ci12e245 ci09b248 ci11d247 ci11d248 ci09b247 ci09b249 ci09b246 ci09b245 ci11d249 ci12e248 ci19l249 ci10c246 ci19l248 ci10c247 ci19l247  ci19l246 ci19l245 ci10c245 ci17j249 ci15h245 ci15h246 ci15h247 ci15h248 ci15h249  ci17j248 ci10c248  ci12e249 ci12e246 ci18k249 ci10c249 ci18k248 ci16i249 ci16i248 ci18k247 ci16i247 ci13f249 ci18k246 ci13f248 ci13f247 ci13f246 ci13f245 ci16i246 ci18k245 ci16i245 ci17j247 ci17j246)
 
 *replace finstrugindex=finstrugindex+1 if arrearsutil==1 Decide whether to expand
 egen yrmoic =rowmax(ci20m_m ci10c_m ci11d_m ci21n_m ci12e_m ci19l_m ci08a_m ci15h_m ci14g_m ci16i_m ci13f_m ci18k_m ci17j_m ci09b_m)
 label variable yrmoic "Year and Month of Income Survey"
 
 gen year=round(yrmoic/100)
 
 keep nomem_encr finstruggle-year
 
 save "incvars.dta", replace
 



*Political Data


 use "cv08a_1.1p_EN.dta", clear
 
 append using "cv09b_2.1p_EN.dta" "cv10c_EN_1.0p.dta" "cv11d_EN_1.0p.dta"  ///
"cv12e_EN_1.0p.dta" "cv13f_EN_1.0p.dta" "cv14g_EN_1.0p.dta" ///
 "cv16h_EN_1.0p.dta" "cv17i_EN_1.0p.dta" "cv18j_EN_1.0p.dta" ///
 "cv19k_EN_1.0p.dta" "cv20l_EN_1.0p.dta" "cv21m_EN_1.0p.dta" "cv22n_EN_1.0p.dta"

 
 *Opinion variables
 egen EU = rowmax(cv08a105   cv09b105   cv10c105   cv11d105   cv12e105   cv13f105   cv14g105   cv16h105   cv17i105   cv18j105   cv19k105   cv20l105   cv21m105 cv22n105)
egen immigration =rowmax(cv08a104	cv09b104	cv10c104	cv11d104	cv12e104	cv13f104	cv14g104	cv16h104	cv17i104	cv18j104	cv19k104	cv20l104	cv21m104 cv22n104 )
egen democracy = rowmax( cv09b044 cv21m044 cv16h044 cv17i044 cv12e044 cv20l044 cv11d044 cv14g044 cv08a044 cv10c044 cv13f044 cv19k044 cv18j044 cv22n044)
egen leftright=rowmax(cv08a101	cv09b101	cv10c101	cv11d101	cv12e101	cv13f101	cv14g101	cv16h101	cv17i101	cv18j101	cv19k101	cv20l101	cv21m101 cv22n101)
egen wilders=rowmax(cv13f224 cv17i224 cv11d185 cv18j224 cv21m224 cv09b096 cv19k224 cv20l224 cv16h224 cv08a096 cv10c096 cv14g224 cv22n224)
egen PVV=rowmax(cv09b085 cv08a085 cv10c085 cv19k213 cv18j213 cv16h213 cv14g213 cv17i213 cv20l213 cv13f213 cv11d175 cv21m213 cv22n213)
egen GL=rowmax(cv08a080 cv10c080 cv09b080 cv19k218 cv14g218 cv21m218 cv13f218 cv18j218 cv20l218 cv16h218 cv11d179 cv17i218 cv22n218)
egen VVD=rowmax(cv21m211 cv18j211 cv13f211 cv19k211 cv20l211 cv11d173 cv14g211 cv12e173 cv16h211 cv17i211 cv08a078 cv09b078 cv10c078 cv22n211)
egen CDA=rowmax(cv17i215 cv21m215 cv12e176 cv08a076 cv14g215 cv11d176 cv10c076 cv18j215 cv20l215 cv19k215 cv13f215 cv09b076 cv16h215 cv22n215)
egen PVDA=rowmax(cv20l212 cv16h212 cv11d174 cv17i212 cv13f212 cv19k212 cv21m212 cv12e174 cv10c077 cv08a077 cv18j212 cv09b077 cv14g212 cv22n212)
egen rutte=rowmax(cv14g222 cv19k222 cv18j222 cv21m222 cv11d183 cv08a089 cv20l222 cv09b089 cv16h222 cv13f222 cv10c089 cv17i222 cv22n222)
egen SP=rowmax(cv10c079 cv13f214 cv21m214 cv20l214 cv12e177 cv19k214 cv16h214 cv11d177 cv14g214 cv09b079 cv17i214 cv08a079 cv18j214 cv22n214) 
egen D66=rowmax(cv16h216 cv13f216 cv19k216 cv12e178 cv21m216 cv17i216 cv18j216 cv14g216 cv20l216 cv11d178 cv10c081 cv08a081 cv09b081 cv22n216)
egen goal1= rowmax(cv08a106 cv09b106 cv10c106 cv11d106 cv12e106 cv13f106 cv14g106 cv16h106 cv17i106 cv18j106 cv19k106 cv20l106 cv21m106 cv22n106)
egen goal2= rowmax(cv08a107 cv09b107 cv10c107 cv11d107 cv12e107 cv13f107 cv14g107 cv16h107 cv17i107 cv18j107 cv19k107 cv20l107 cv21m107 cv22n107)
egen goal3= rowmax(cv08a108 cv09b108 cv10c108 cv11d108 cv12e108 cv13f108 cv14g108 cv16h108 cv17i108 cv18j108 cv19k108 cv20l108 cv21m108 cv22n108)
 

  
 *Date
egen datum = concat( cv08a161	cv09b161	cv10c161	cv11d161	cv12e161	cv13f161	cv14g161	DatumB DatumB_lang DatumB_deel1 DatumB_deelh DatumB_deeli DatumB_deelg	cv17i161	cv18j289	cv19k289	cv20l289	cv21m289 cv22n289)
gen stdate=date(datum,"DM20Y")
format stdate %td
*Deal with missing dates
gen mhelp=0
replace mhelp=1 if datum==""
*Month year variable
gen myear=ym(year(stdate), month(stdate)) 
format myear %tm

gen year=year(stdate)
gen month=month(stdate)
replace year=year-1 if month<4
replace year=2021 if cv22n289 !=""
replace year=2020 if cv21m289 !=""
replace year=2019 if cv20l289 !=""
replace year=2018 if cv19k289 !=""
replace year=2017 if cv18j289 !=""

replace year=2016 if cv17i161 !=""
replace year=2015 if DatumB !=""
replace year=2015 if DatumB_lang !=""
replace year=2015 if DatumB_deel1 !=""
replace year=2015 if DatumB_deeli !=""
replace year=2015 if DatumB_deelg !=""
replace year=2015 if DatumB_deelh !=""

replace year=2013 if cv14g161 !=""
replace year=2012 if cv13f161 !=""
replace year=2011 if cv12e161 !=""

replace year=2010 if cv11d161 !=""
replace year=2009 if cv10c161 !=""
replace year=2008 if cv09b161 !=""
replace year=2007 if cv08a161 !=""




sort year




 mvdecode wilders GL PVV rutte PVDA CDA D66 VVD  EU democracy immigration leftright SP, mv(-9 99 999)
egen Sympmax=rowmax(GL VVD CDA D66 PVDA )
egen Sympmean=rowmean (GL VVD CDA D66 PVDA)
gen PVVsympmax=PVV-Sympmax
gen PVVsympmean=PVV-Sympmean

 

*Voting variables

decode cv08a058, gen(e1)
decode cv09b058, gen(e2)
decode cv10c058, gen(e3)
decode cv11d171, gen(e4)
decode cv12e171, gen(e5)
decode cv13f209, gen(e6)
decode cv14g209, gen(e7)
decode cv16h209, gen(e8)
decode cv17i244, gen(e9)
decode cv18j308, gen(e10)
decode cv19k308, gen(e11)
decode cv20l308, gen(e12)
decode cv21m308, gen(e13)
decode cv22n308, gen(e14)
egen votechoice = concat( e1-e14)

gen extremeright=0
replace extremeright=1 if strpos(votechoice,"Wilders")>0
replace extremeright=1 if strpos(votechoice,"Verdonk")>0
replace extremeright=1 if strpos(votechoice,"Forum")>0
replace extremeright=1 if strpos(votechoice,"JA21")>0
replace extremeright=-99 if strpos(votechoice,"vote")>0
replace extremeright=-99 if strpos(votechoice,"know")>0
replace extremeright=-99 if votechoice==""
replace extremeright=. if extremeright==-99

gen GroenLinks=0
replace GroenLinks=1 if strpos(votechoice,"Groen")>0
replace GroenLinks=. if extremeright==.
 
*Vote chance variables in later surveys
egen maxvot17=rowmax(cv17i245 - cv17i262)
replace extremeright=0 if maxvot17>0 & maxvot17<101
replace extremeright=. if cv17i245==maxvot17 &  maxvot17!=.
replace extremeright=1 if cv17i248==maxvot17 &  maxvot17!=.

replace GroenLinks=0 if maxvot17>0 & maxvot17<101
replace GroenLinks=1 if cv17i253==maxvot17 &  maxvot17!=.

egen maxvot18=rowmax(cv18j245 - cv18j304)
replace extremeright=0 if maxvot18>0 & maxvot18<101
replace extremeright=. if cv18j245==maxvot18 &  maxvot18!=.
replace extremeright=1 if cv18j248==maxvot18 & maxvot18!=.
replace extremeright=1 if cv18j304==maxvot18 & maxvot18!=.
 replace GroenLinks=0 if maxvot18>0 & maxvot18<101
replace GroenLinks=1 if cv18j253==maxvot18 &  maxvot18!=.

egen maxvot19=rowmax(cv19k245 - cv19k304)
replace extremeright=0 if maxvot19>0 & maxvot19<101
replace extremeright=. if cv19k245==maxvot19 &  maxvot19!=.
replace extremeright=1 if cv19k248==maxvot19 &  maxvot19!=.
replace extremeright=1 if cv19k304==maxvot19 & maxvot19!=.
 replace GroenLinks=0 if maxvot19>0 & maxvot19<101
replace GroenLinks=1 if cv19k253==maxvot19 &  maxvot19!=.
 
egen maxvot20=rowmax(cv20l245 - cv20l304)
replace extremeright=0 if maxvot20>0 & maxvot20<101
replace extremeright=. if cv20l245==maxvot20 &  maxvot20!=.
replace extremeright=1 if cv20l248==maxvot20 &  maxvot20!=.
replace extremeright=1 if cv20l304==maxvot20 & maxvot20!=.
 replace GroenLinks=0 if maxvot20>0 & maxvot20<101
replace GroenLinks=1 if cv20l253==maxvot20 &  maxvot20!=.

egen maxvot21=rowmax(cv21m245 - cv21m304)
replace extremeright=0 if maxvot21>0 & maxvot21<101
replace extremeright=. if cv21m245==maxvot21 &  maxvot21!=.
replace extremeright=1 if cv21m248==maxvot21 &  maxvot21!=.
replace extremeright=1 if cv21m304==maxvot21 & maxvot21!=.

 replace GroenLinks=0 if maxvot21>0 & maxvot21<101
replace GroenLinks=1 if cv21m253==maxvot21 &  maxvot21!=.
 
egen maxvot22=rowmax(cv22n245 - cv22n324)
replace extremeright=0 if maxvot22>0 & maxvot22<101
replace extremeright=. if cv22n245==maxvot22 &  maxvot22!=.
replace extremeright=1 if cv22n248==maxvot22 &  maxvot22!=.
replace extremeright=1 if cv22n304==maxvot22 & maxvot22!=.
replace extremeright=1 if cv22n322==maxvot22 & maxvot22!=.
 replace GroenLinks=0 if maxvot22>0 & maxvot22<101
replace GroenLinks=1 if cv22n253==maxvot22 &  maxvot22!=.
 

 gen Paris=0
 replace Paris=1 if year>2014
 
 keep nomem_encr EU-Paris
 
  save "Polpanel.dta", replace
*Fix missing year values!!!!
  drop if year==.
  duplicates drop nomem_encr year, force

   merge 1:1 nomem_encr year using "incvars.dta"
      drop if _merge==2
	  drop _merge
	   merge 1:1 nomem_encr year using "housevars.dta"
      drop if _merge==2
	  drop _merge  
	  
	  	   merge 1:1 nomem_encr year using "backvars.dta"
      drop if _merge==2
	  drop _merge  
	  
	 
    save "LisspanelFinal.dta", replace
   
  use  "LisspanelFinal.dta", clear
merge m:1 dwelling aantalhh using "GWEmonthly.dta"

drop _merge

 merge m:1 year using "GWECBSCPI.dta"
 drop _merge
 
 gen GWEmonthly=GWEmonth*GWEmultiplier
save "LisspanelFinal.dta", replace

